package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import view.MainMenuPage;
import dto.LogonDTO;

public class MenuController {

	private UserController userController;
	private AddBookController addController;
	private SearchBookController searchController;
	private BorrowReturnBookController borrowReturnController;

	void showMenu(LogonDTO logonDTO) {

		final LogonDTO dto = logonDTO;

		userController = new UserController();
		addController = new AddBookController();
		searchController = new SearchBookController();
		borrowReturnController = new BorrowReturnBookController();

		MainMenuPage mainMenu = new MainMenuPage(logonDTO);

		mainMenu.addAddUserButtonListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userController.addUser(dto);

			}
		});

		mainMenu.addEditDelUserButtonListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userController.searchUser(dto);

			}
		});

		mainMenu.addAddBookButtonListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addController.addBook(dto);

			}
		});

		mainMenu.addEditDelBookButtonListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				searchController.searchForBook(dto, "EDIT");

			}
		});

		mainMenu.addBorrowReturnBookButtonListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				borrowReturnController.borrowReturnBook(dto);

			}
		});

		mainMenu.addSearchForBookButtonListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				searchController.searchForBook(dto, "SEARCH");

			}
		});
	}
}
